//////// comments ///////

#include <vector>
#include "combined.h"
#include "command.h"
#include "commandTable.h"
#include "definitions.h"
#include "log.h"
#include "stringutil.h"
#include "timestamp.h"
#include "tEditHandler.h"
#include "world.h"

// Medit Command definitions...
// (Keep in alphabetical order... it's MUCH easier)
mCmdAc::mCmdAc( void ) {
	setName( "ac" );
	setLevel( BUILDER );
	setEnabled( true );
	setOmniset( false );
	setTags( "ac medit" );
	addSyntax( "syntax: ac <value>    {Cset the current mobs ac to the given value" );
}

bool mCmdAc::execute( Character* character, const std::string& args ) {

	if ( args.empty() ) {
		character->Send( getSyntax() );
		return false;
	}

	character->getMob()->setAc( atoi( args.c_str() ) );
	mCmdView cmdView;
	cmdView.execute( character, "null" );

	return true;
}

mCmdAcBash::mCmdAcBash( void ) {
	setName( "acbash" );
	setLevel( BUILDER );
	setEnabled( true );
	setOmniset( false );
	setTags( "acbash medit" );
	addSyntax( "syntax: acbash <value>   {Cset the current mobs ac (bash) to the given value" );
}

bool mCmdAcBash::execute( Character* character, const std::string& args ) {

	if ( args.empty() ) {
		character->Send( getSyntax() );
		return false;
	}

	character->getMob()->setAcBash( atoi( args.c_str() ) );
	mCmdView cmdView;
	cmdView.execute( character, "null" );

	return true;
}

mCmdAcSlash::mCmdAcSlash( void ) {
	setName( "acslash" );
	setLevel( BUILDER );
	setEnabled( true );
	setOmniset( false );
	setTags( "acslash medit" );
	addSyntax( "syntax: acslash <value>   {Cset the current mobs ac (slash) to the given value" );
}

bool mCmdAcSlash::execute( Character* character, const std::string& args ) {

	if ( args.empty() ) {
		character->Send( getSyntax() );
		return false;
	}

	character->getMob()->setAcSlash( atoi( args.c_str() ) );
	mCmdView cmdView;
	cmdView.execute( character, "null" );

	return true;
}

mCmdAcPierce::mCmdAcPierce( void ) {
	setName( "acpierce" );
	setLevel( BUILDER );
	setEnabled( true );
	setOmniset( false );
	setTags( "acpierce medit" );
	addSyntax( "syntax: acpierce <value>   {Cset the current mobs ac (pierce) to the given value" );
}

bool mCmdAcPierce::execute( Character* character, const std::string& args ) {

	if ( args.empty() ) {
		character->Send( getSyntax() );
		return false;
	}

	character->getMob()->setAcPierce( atoi( args.c_str() ) );
	mCmdView cmdView;
	cmdView.execute( character, "null" );

	return true;
}

mCmdAcExotic::mCmdAcExotic( void ) {
	setName( "acexotic" );
	setLevel( BUILDER );
	setEnabled( true );
	setOmniset( false );
	setTags( "acexotic medit" );
	addSyntax( "syntax: acexotic <value>   {Cset the current mobs charisma to the given value" );
}

bool mCmdAcExotic::execute( Character* character, const std::string& args ) {

	if ( args.empty() ) {
		character->Send( getSyntax() );
		return false;
	}

	character->getMob()->setAcExotic( atoi( args.c_str() ) );
	mCmdView cmdView;
	cmdView.execute( character, "null" );

	return true;
}

mCmdCharisma::mCmdCharisma( void ) {
	setName( "charisma" );
	setLevel( BUILDER );
	setEnabled( true );
	setOmniset( false );
	setTags( "charisma medit" );
	addSyntax( "syntax: charisma <value>   {Cset the current mobs charisma to the given value" );
}

bool mCmdCharisma::execute( Character* character, const std::string& args ) {

	if ( args.empty() ) {
		character->Send( getSyntax() );
		return false;
	}

	character->getMob()->setMaxCha( atoi( args.c_str() ) );
	mCmdView cmdView;
	cmdView.execute( character, "null" );

	return true;
}

mCmdClass::mCmdClass( void ) {
	setName( "class" );
	setLevel( BUILDER );
	setEnabled( true );
	setOmniset( false );
	setTags( "class medit" );
	addSyntax( "syntax: class <value>   {Cset the current mobs class to the given value" );
}

bool mCmdClass::execute( Character* character, const std::string& args ) {
	std::string tmp = trim( args );

	if ( args.empty() ) {
		character->Send( getSyntax() );
		return false;
	}

	character->getMob()->setClass( Creature::string2class( tmp ) );
	mCmdView cmdView;
	cmdView.execute( character, "null" );

	return true;
}

mCmdCommands::mCmdCommands( void ) {
	setName( "commands" );
	setLevel( 1 );
	setEnabled( true );
	setOmniset( false );
	setTags( "commands medit" );
	addSyntax( "sytnax: commands    {Clist all current commands" );
}

bool mCmdCommands::execute( Character* character, const std::string& args ) {
	std::string buf;
	std::string temp;
	unsigned i=0;

	// HEAD Commands...
	if ( character->getLevel() >= HEAD ) {
		buf << "\n\r\t{cHead commands:{x\n\r";
		for ( std::vector< Command* >::iterator it = mCommandTable::Instance().getCommands().begin(); it != mCommandTable::Instance().getCommands().end(); ++it ) {
			if ( (*it)->getLevel() == HEAD ) {
				if ( i % 6 == 0 ) {
					if ( i )
						buf << "\n\r";
					buf << "  ";
				}
				if ( (*it)->getEnabled() )
					buf << format( 12, (*it)->getName(), temp );
				else
					buf << format( 12, (*it)->getName(), temp, 'w' );
				i++;
			}
		}
	}

	// GOD Commands...
	if ( character->getLevel() >= GOD ) {
		i = 0;
		buf << "\n\r\t{cGod commands:{x\n\r";
		for ( std::vector< Command* >::iterator it = mCommandTable::Instance().getCommands().begin(); it != mCommandTable::Instance().getCommands().end(); ++it ) {
			if ( (*it)->getLevel() == GOD ) {
				if ( i % 6 == 0 ) {
					if ( i )
						buf << "\n\r";
					buf << "  ";
				}
				if ( (*it)->getEnabled() )
					buf << format( 12, (*it)->getName(), temp );
				else
					buf << format( 12, (*it)->getName(), temp, 'w' );
				i++;
			}
		}
	}

	// BUILDER Commands...
	if ( character->getLevel() >= BUILDER ) {
		i = 0;
		buf << "\n\r\t{cBuilder commands:{x\n\r";
		for ( std::vector< Command* >::iterator it = mCommandTable::Instance().getCommands().begin(); it != mCommandTable::Instance().getCommands().end(); ++it ) {
			if ( (*it)->getLevel() == BUILDER ) {
				if ( i % 6 == 0 ) {
					if ( i )
						buf << "\n\r";
					buf << "  ";
				}
				if ( (*it)->getEnabled() )
					buf << format( 12, (*it)->getName(), temp );
				else
					buf << format( 12, (*it)->getName(), temp, 'w' );
				i++;
			}
		}
	}

	// Regular Commands...
	buf << "\n\r\t{c-- Commands --{x \n\r";
	i = 0;
	for ( std::vector< Command* >::iterator it = mCommandTable::Instance().getCommands().begin(); it != mCommandTable::Instance().getCommands().end(); ++it ) {
		if ( (*it)->getLevel() == 1 ) {
			if ( i % 6 == 0 ) {
				if ( i )
					buf << "\n\r";
				buf << "  ";
			}
			if ( (*it)->getEnabled() )
				buf << format( 12, (*it)->getName(), temp );
			else
				buf << format( 12, (*it)->getName(), temp, 'w' );
			i++;
		}
	}

	character->Send( buf );

	return true;
}

mCmdConstitution::mCmdConstitution( void ) {
	setName( "constitution" );
	setLevel( BUILDER );
	setEnabled( true );
	setOmniset( false );
	setTags( "constitution medit" );
	addSyntax( "syntax: constitution <value>   {Cset the current mobs constitution to the given value" );
}

bool mCmdConstitution::execute( Character* character, const std::string& args ) {

	if ( args.empty() ) {
		character->Send( getSyntax() );
		return false;
	}

	character->getMob()->setMaxCon( atoi( args.c_str() ) );
	mCmdView cmdView;
	cmdView.execute( character, "null" );

	return true;
}

mCmdDamroll::mCmdDamroll( void ) {
	setName( "damroll" );
	setLevel( BUILDER );
	setEnabled( true );
	setOmniset( false );
	setTags( "damroll medit" );
	addSyntax( "syntax: damroll <value>   {Cset the current mobs damroll to the given value" );
}

bool mCmdDamroll::execute( Character* character, const std::string& args ) {

	if ( args.empty() ) {
		character->Send( getSyntax() );
		return false;
	}

	character->getMob()->setDr( atoi( args.c_str() ) );
	mCmdView cmdView;
	cmdView.execute( character, "null" );

	return true;
}

mCmdDescription::mCmdDescription( void ) {
	setName( "description" );
	setLevel( BUILDER );
	setEnabled( true );	
	setOmniset( false );
	setTags( "description medit" );
	addSyntax( "syntax: description    {Center the text editor for the current mobs description" );
}

bool mCmdDescription::execute( Character* character, const std::string& args ) {

	character->setTedit( true );
	tEditList::Instance().act( character, args );

	return true;
}

mCmdDexterity::mCmdDexterity( void ) {
	setName( "dexterity" );
	setLevel( BUILDER );
	setEnabled( true );
	setOmniset( false );
	setTags( "dexterity medit" );
	addSyntax( "syntax: dexterity <value>   {Cset the current mobs dexterity to the given value" );
}

bool mCmdDexterity::execute( Character* character, const std::string& args ) {

	if ( args.empty() ) {
		character->Send( getSyntax() );
		return false;
	}

	character->getMob()->setMaxDex( atoi( args.c_str() ) );
	mCmdView cmdView;
	cmdView.execute( character, "null" );

	return true;
}

mCmdExit::mCmdExit( void ) {
	setName( "exit" );
	setLevel( BUILDER );
	setEnabled( true );
	setOmniset( false );
	setTags( "exit medit" );
	addSyntax( "syntax: exit    {Cexit medit mode" );
}

bool mCmdExit::execute( Character* character, const std::string& args ) {

	character->setStatus( CONNECTED );
	character->setMob( NULL );
	character->Send( "You have left Medit mode." );

	return true;
}

mCmdGender::mCmdGender( void ) {
	setName( "gender" );
	setLevel( BUILDER );
	setEnabled( true );
	setOmniset( false );
	setTags( "gender medit" );
	addSyntax( "syntax: gender <value>   {Cset the current mobs gender to the given value" );
}

bool mCmdGender::execute( Character* character, const std::string& args ) {
	std::string tmp = trim( args );

	if ( args.empty() ) {
		character->Send( getSyntax() );
		return false;
	}

	character->getMob()->setGender( Creature::string2gender( tmp ) );
	mCmdView cmdView;
	cmdView.execute( character, "null" );

	return true;
}

mCmdHp::mCmdHp( void ) {
	setName( "hp" );
	setLevel( BUILDER );
	setEnabled( true );
	setOmniset( false );
	setTags( "hp medit" );
	addSyntax( "syntax: hp <value>   {Cset the current mobs hp to the given value" );
}

bool mCmdHp::execute( Character* character, const std::string& args ) {

	if ( args.empty() ) {
		character->Send( getSyntax() );
		return false;
	}

	character->getMob()->setMaxHp( atoi( args.c_str() ) );
	mCmdView cmdView;
	cmdView.execute( character, "null" );

	return true;
}

mCmdHitroll::mCmdHitroll( void ) {
	setName( "hitroll" );
	setLevel( BUILDER );
	setEnabled( true );
	setOmniset( false );
	setTags( "hitroll medit" );
	addSyntax( "syntax: hitroll <value>   {Cset the current mobs hitroll to the given value" );
}

bool mCmdHitroll::execute( Character* character, const std::string& args ) {

	if ( args.empty() ) {
		character->Send( getSyntax() );
		return false;
	}

	character->getMob()->setHr( atoi( args.c_str() ) );
	mCmdView cmdView;
	cmdView.execute( character, "null" );

	return true;
}

mCmdIntelligence::mCmdIntelligence( void ) {
	setName( "intelligence" );
	setLevel( BUILDER );
	setEnabled( true );
	setOmniset( false );
	setTags( "intelligence medit" );
	addSyntax( "syntax: intelligence <value>   {Cset the current mobs intelligence to the given value" );
}

bool mCmdIntelligence::execute( Character* character, const std::string& args ) {

	if ( args.empty() ) {
		character->Send( getSyntax() );
		return false;
	}

	character->getMob()->setMaxIntel( atoi( args.c_str() ) );
	mCmdView cmdView;
	cmdView.execute( character, "null" );

	return true;
}

mCmdLevel::mCmdLevel( void ) {
	setName( "level" );
	setLevel( BUILDER );
	setEnabled( true );
	setOmniset( false );
	setTags( "level medit" );
	addSyntax( "syntax: level <value>   {Cset the current mobs level to the given value" );
}

bool mCmdLevel::execute( Character* character, const std::string& args ) {

	if ( args.empty() ) {
		character->Send( "syntax: level <number>\n\r" );
		return false;
	}

	character->getMob()->setLevel( atoi( args.c_str() ) );
	mCmdView cmdView;
	cmdView.execute( character, "null" );

	return true;
}

mCmdLong::mCmdLong( void ) {
	setName( "long" );
	setLevel( BUILDER );
	setEnabled( true );
	setOmniset( false );
	setTags( "long medit" );
	addSyntax( "syntax: long <string>  {Cchange the current mobs long description to <string>" );
}

bool mCmdLong::execute( Character* character, const std::string& args ) {
	std::string tmp = trim( args );

	if ( args.empty() ) {
		character->Send( getSyntax() );
		return false;
	}

	character->getMob()->setLongDesc( tmp );
	mCmdView cmdView;
	cmdView.execute( character, "null" );

	return true;
}

mCmdMana::mCmdMana( void ) {
	setName( "mana" );
	setLevel( BUILDER );
	setEnabled( true );
	setOmniset( false );
	setTags( "mana medit" );
	addSyntax( "syntax: mana <value>   {Cset the current mobs mana points to value" );
}

bool mCmdMana::execute( Character* character, const std::string& args ) {

	if ( args.empty() ) {
		character->Send( getSyntax() );
		return false;
	}

	character->getMob()->setMaxMana( atoi( args.c_str() ) );
	mCmdView cmdView;
	cmdView.execute( character, "null" );

	return true;
}

mCmdMove::mCmdMove( void ) {
	setName( "move" );
	setLevel( BUILDER );
	setEnabled( true );
	setOmniset( false );
	setTags( "move medit" );
	addSyntax( "syntax: move <value>   {Cset the current mobs movement points to value" );
}

bool mCmdMove::execute( Character* character, const std::string& args ) {

	if ( args.empty() ) {
		character->Send( getSyntax() );
		return false;
	}

	character->getMob()->setMaxMove( atoi( args.c_str() ) );
	mCmdView cmdView;
	cmdView.execute( character, "null" );

	return true;
}

mCmdName::mCmdName( void ) {
	setName( "name" );
	setLevel( BUILDER );
	setEnabled( true );
	setOmniset( false );
	setTags( "name medit" );
	addSyntax( "syntax: name <string>   {Cset the name of the current mob to the given string" );
}

bool mCmdName::execute( Character* character, const std::string& args ) {
	std::string tmp = trim( args );

	if ( args.empty() ) {
		character->Send( getSyntax() );
		return false;
	}

	character->getMob()->setName( tmp );
	mCmdView cmdView;
	cmdView.execute( character, "null" );

	return true;
}

mCmdRace::mCmdRace( void ) {
	setName( "race" );
	setLevel( BUILDER );
	setEnabled( true );
	setOmniset( false );
	setTags( "race medit" );
	addSyntax( "syntax: race <value>   {Cchange the current mobs race to the given value" );
}

bool mCmdRace::execute( Character* character, const std::string& args ) {
	std::string tmp = trim( args );

	if ( tmp.empty() ) {
		character->Send( getSyntax() );
		return false;
	}

	character->getMob()->setRace( Creature::string2race( tmp ) );
	mCmdView cmdView;
	cmdView.execute( character, "null" );

	return true;
}

mCmdSaves::mCmdSaves( void ) {
	setName( "saves" );
	setLevel( BUILDER );
	setEnabled( true );
	setOmniset( false );
	setTags( "saves medit" );
	addSyntax( "syntax: saves <value>   {Cset the current mobs saves to the given value" );
}

bool mCmdSaves::execute( Character* character, const std::string& args ) {

	if ( args.empty() ) {
		character->Send( getSyntax() );
		return false;
	}

	character->getMob()->setSaves( atoi( args.c_str() ) );
	mCmdView cmdView;
	cmdView.execute( character, "null" );

	return true;
}

mCmdShort::mCmdShort( void ) {
	setName( "short" );
	setLevel( BUILDER );
	setEnabled( true );
	setOmniset( false );
	setTags( "short medit" );
	addSyntax( "syntax: short <string>  {Cchange the current mobs short description to <string>" );
}

bool mCmdShort::execute( Character* character, const std::string& args ) {
	std::string tmp = trim( args );

	if ( args.empty() ) {
		character->Send( getSyntax() );
		return false;
	}

	character->getMob()->setShortDesc( tmp );
	mCmdView cmdView;
	cmdView.execute( character, "null" );

	return true;
}

mCmdStrength::mCmdStrength( void ) {
	setName( "str" );
	setLevel( BUILDER );
	setEnabled( true );
	setOmniset( false );
	setTags( "strength medit" );
	addSyntax( "syntax: strength <value>   {Cset the current mobs strength to the given value" );
}

bool mCmdStrength::execute( Character* character, const std::string& args ) {

	if ( args.empty() ) {
		character->Send( getSyntax() );
		return false;
	}

	character->getMob()->setMaxStr( atoi( args.c_str() ) );
	mCmdView cmdView;
	cmdView.execute( character, "null" );

	return true;
}

mCmdView::mCmdView( void ) {
	setName( "view" );
	setLevel( BUILDER );
	setEnabled( true );
	setOmniset( false );
	setTags( "view medit" );
	addSyntax( "syntax: view    {Cdisplay data for the current mob" );
}

bool mCmdView::execute( Character* character, const std::string& args ) {
	std::string buf;
	Mob* mob = character->getMob();

	buf << "{Cac:{x        " << format( 25, mob->getAc() );
	buf << "{Cac bash:{x   " << format( 25, mob->getAcBash() ) << "\n\r";
	buf << "{Cac slash:{x  " << format( 25, mob->getAcSlash() );
	buf << "{Cac pierce:{x " << format( 25, mob->getAcPierce() ) << "\n\r";
	buf << "{Cac exotic:{x " << format( 25, mob->getAcExotic() );
	buf << "{Ccha:{x       " << format( 25, mob->getMaxCha() ) << "\n\r";
	buf << "{Cclass:{x     " << format( 25, Creature::class2string( mob->getClass() ) );
	buf << "{Ccon:{x       " << format( 25, mob->getMaxCon() ) << "\n\r";
	buf << "{Cdr:{x        " << format( 25, mob->getDr() );
	buf << "{Cdex:{x       " << format( 25, mob->getMaxDex() ) << "\n\r";
	buf << "{Cgender:{x    " << format( 25, Creature::gender2string( mob->getGender() ) );
	buf << "{Chp:{x        " << format( 25, mob->getMaxHp() ) << "\n\r";
	buf << "{Chr:{x        " << format( 25, mob->getHr() );
	buf << "{Cint:{x       " << format( 25, mob->getMaxIntel() ) << "\n\r";
	buf << "{Clevel:{x     " << format( 25, mob->getLevel() );
	buf << "{Clong:{x      " << format( 25, mob->getLongDesc() ) << "\n\r";
	buf << "{Cmana:{x      " << format( 25, mob->getMaxMana() );
	buf << "{Cmove:{x      " << format( 25, mob->getMaxMove() ) << "\n\r";
	buf << "{Cname:{x      " << format( 25, mob->getName() );
	buf << "{Crace:{x      " << format( 25, Creature::race2string( mob->getRace() ) ) << "\n\r";
	buf << "{Csaves:{x     " << format( 25, mob->getSaves() );
	buf << "{Cshort:{x     " << format( 25, mob->getShortDesc() ) << "\n\r";
	buf << "{Cstr:{x       " << format( 25, mob->getMaxStr() );
	buf << "{Cvnum:{x      " << format( 25, mob->getVnum() ) << "\n\r";
	buf << "{Cwimpy:{x     " << format( 25, mob->getWimpy() );
	buf << "{Cwis:{x       " << format( 25, mob->getMaxWis() ) << "\n\r";
	buf << "{Cheight:{x    " << format( 25, mob->getStrHeight() );
	buf << "{Cweight:{x    " << format( 25, mob->getStrWeight() ) << "\n\r";
	buf << "{CDescription:{x\n\r" << mob->getFullDesc();

	character->Send( buf );

	return true;
}

mCmdWimpy::mCmdWimpy( void ) {
	setName( "wimpy" );
	setLevel( BUILDER );
	setEnabled( true );
	setOmniset( false );
	setTags( "wimpy medit" );
	addSyntax( "sytnax: wimpy <value>   {Cset the current mobs wimpy to the given value" );
}

bool mCmdWimpy::execute( Character* character, const std::string& args ) {

	if ( args.empty() ) {
		character->Send( getSyntax() );
		return false;
	}

	character->getMob()->setWimpy( atoi( args.c_str() ) );
	mCmdView cmdView;
	cmdView.execute( character, "null" );

	return true;
}

mCmdWisdom::mCmdWisdom( void ) {
	setName( "wisdom" );
	setLevel( BUILDER );
	setEnabled( true );
	setOmniset( false );
	setTags( "wisdom medit" );
	addSyntax( "syntax: wisdom <value>    {Cset the current mobs wisdom to the given value\n" );
}

bool mCmdWisdom::execute( Character* character, const std::string& args ) {

	if ( args.empty() ) {
		character->Send( getSyntax() );
		return false;
	}

	character->getMob()->setMaxWis( atoi( args.c_str() ) );
	mCmdView cmdView;
	cmdView.execute( character, "null" );

	return true;
}
